package com.ltmonitor.service;

import javax.servlet.http.HttpServlet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ltmonitor.thread.BtdTimeThread;

import java.lang.Thread;



/**
 * 在系统准备完成后需要启动的服务
 * @author shinion
 *
 */

public class StartServiceAfterReady extends HttpServlet {
	
	
	
	private BtdTimeThread timerThread  = null;
	
	//首先执行
	public void init() {
		try {
			
//			System.out.println("++++++++++++++++++++++++++++++++");
//			System.out.println("++++++++++++++++++++++++++++++++");
//			System.out.println("开始加载");
			
			//1.加载定时执行线程
			if(timerThread == null) {
				timerThread = new BtdTimeThread();
				timerThread.start();
				System.out.println("加载定时器线程完成!");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	
	//销毁执行
	public void destroy() {
		try {
			System.out.println("++++++++++++++++++++++++++++++++");
			System.out.println("++++++++++++++++++++++++++++++++");
			System.out.println("开始销毁");
			//停止线程
			if(timerThread != null) {
				timerThread.setThreadFlg(false);
				timerThread = null;
			}
			
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		
	}
}
